package org.jeecg.modules.inspection.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.inspection.entity.PinspectionItem;
import org.jeecg.modules.inspection.entity.PinspetionArea;
import org.jeecg.modules.inspection.vo.InspetionAreaPoint;
import org.jeecg.modules.inspection.vo.InspetionDetails;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 巡检区域
 * @Author: jeecg-boot
 * @Date:   2019-09-26
 * @Version: V1.0
 */
@Repository
public interface PinspetionAreaMapper extends BaseMapper<PinspetionArea> {

    @SqlParser(filter = true)
    void insertBatch(@Param("infos") List<PinspetionArea> areas);


    void  updateStatus(PinspetionArea pinspetionArea);
    @Update("UPDATE process_inspection_area set is_check_res = #{res} where id = #{areaId} AND del_flag ='0'")
    void updateRes(@Param("areaId")String areaId,@Param("res")Integer res);

    @Select("SELECT process_longitude as lng,process_dimension as lat,name FROM process_inspection_area WHERE process_id = #{lineId} AND process_dimension is not null AND process_longitude is not null ORDER BY number ASC")
    List<InspetionAreaPoint> selectListPointByLineId(@Param("lineId") String lineId);

    @Select("SELECT pii.id,pii.name as itemName,pia.name as areaName,sd.depart_name as officeName,bp.name as projectName,\n" +
            "bf.name as floorName,pia.tire,pii.is_check,pii.is_check_res,pii.exec_comfirm_status,pii.update_time FROM process_inspection_area pia \n" +
            "LEFT JOIN process_inspection_item pii on pii.process_area_id = pia.id\n" +
            "LEFT JOIN sys_depart sd on sd.id = pia.office_id\n" +
            "LEFT JOIN base_project bp on bp.id = pia.project_id\n" +
            "LEFT JOIN base_floor bf on bf.id = pia.floor_id\n" +
            "WHERE pia.process_id = #{lineId} ORDER BY pia.number,pii.number")
    List<InspetionDetails> queryAreaItems(@Param("lineId") String lineId);

    List<PinspetionArea> selectAllItem(@Param("processId") String processId);

    @SqlParser(filter = true)
    Integer updateToOutTime(@Param("ids") List<String> ids);
    @Select("select * from process_inspection_item where process_area_id = #{processAreaId} and del_flag ='0'")
    List<PinspectionItem> selectItem(@Param("processAreaId") String processAreaId);
}
